//
//  RHLocalChartHeaderView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/6/25.
//

#import "RHLocalChartHeaderView.h"
#import "RHLocalEndpointModel.h"
#import "RHEndPointTypeModel.h"

@interface RHLocalChartHeaderView()
@property (nonatomic, strong) QMUILabel *snTitleLab;

@property (nonatomic, strong) QMUILabel *snContentLab;

@property (nonatomic, strong) QMUILabel *versionTitleLab;

@property (nonatomic, strong) QMUILabel *versionContentLab;

@property (nonatomic ,strong) UIView *pointView;
@end
@implementation RHLocalChartHeaderView

-(instancetype)init
{
    if(self = [super init]){
        [self setupUI];
    }
    return self;
}


-(void)setEndPointModel:(RHLocalEndpointModel *)endPointModel
{
    _endPointModel = endPointModel;
    self.snTitleLab.text = [NSString stringWithFormat:@"%@ SN:",ValidNullData(self.endpointName)];
    self.snContentLab.text = endPointModel.sn;
    self.versionTitleLab.text = [NSString stringWithFormat:@"%@:",@"版本".rh_localized];
    
    self.versionContentLab.text = [NSString stringWithFormat:@"S:V%@/H:V%@",ValidNullDataToString(endPointModel.lastVersion, @"--"),ValidNullDataToString(endPointModel.hardVersion, @"--")];
    
    if(endPointModel.state == 1){//在线
        _pointView.backgroundColor = CMainColorGreen;
        _snContentLab.textColor = CMainColorGreen;
    }else if (endPointModel.state == 2){//失联
        _pointView.backgroundColor = kCOLOR_HEX(@"BBBBBB");
        _snContentLab.textColor = kCOLOR_HEX(@"BBBBBB");
    }
}


- (void)setupUI{
    kWeakSelf;
    self.backgroundColor = CFTabViewBgColor;
    self.frame = CGRectMake(0, 10, SCREEN_WIDTH,140);
    UIView *bgView =  [[UIView alloc] initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30,140)];
    [bgView setBackgroundColor:UIColor.whiteColor];
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    bgView.layer.masksToBounds = kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsMake(10, 15, 0, 15));
    }];

    
    
    UIView *contentView1 = [[UIView alloc] init];
    [contentView1 setBackgroundColor:UIColor.clearColor];
    [bgView addSubview:contentView1];
    [contentView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(0);
        make.height.offset(kScaleW(45));
    }];
    
    _snTitleLab = [[QMUILabel alloc]init];
    [contentView1 addSubview:_snTitleLab];
    _snTitleLab.text = @"SN:";
    _snTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    _snTitleLab.font = kSYSTEMFONT(14);
    _snTitleLab.textAlignment = NSTextAlignmentLeft;
    [_snTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
    }];
    
    _arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow"]];
    [contentView1 addSubview:_arrowImg];
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.right.mas_offset(-10);
        make.centerY.mas_offset(0);
    }];
    
    _snContentLab = [[QMUILabel alloc]init];
    [contentView1 addSubview:_snContentLab];
    _snContentLab.text = @"--";
    _snContentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    _snContentLab.font = kSYSTEMFONT(14);
    _snContentLab.textAlignment = NSTextAlignmentRight;
    [_snContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.arrowImg.mas_left).offset(-5);
        make.centerY.mas_offset(0);
    }];
    
    _pointView = [[UIView alloc]init];
    _pointView.layer.cornerRadius = 3;
    _pointView.layer.masksToBounds = YES;
    [contentView1 addSubview:_pointView];
    [_pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(6);
        make.centerY.mas_offset(0);
        make.right.equalTo(weakSelf.snContentLab.mas_left).offset(-3);
    }];
    
    
    QMUIButton *btn = [[QMUIButton alloc]init];
    [contentView1 addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.selectBlock){
            weakSelf.selectBlock();
        }
    }];
    
    UIView *line = kView;
    [bgView addSubview:line];
    line.backgroundColor = kCOLOR_HEX(@"E7E7E7");
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(contentView1.mas_bottom);
        make.height.offset(1);
    }];
    
    UIView *contentView2 = [[UIView alloc] init];
    [contentView2 setBackgroundColor:UIColor.clearColor];
    [self addSubview:contentView2];
    [contentView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentView1);
        make.top.equalTo(contentView1.mas_bottom);
        make.height.equalTo(contentView1);
    }];
    
    _versionTitleLab = [[QMUILabel alloc]init];
    [contentView2 addSubview:_versionTitleLab];
    _versionTitleLab.text = @"版本".rh_localized;
    _versionTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    _versionTitleLab.font = kSYSTEMFONT(14);
    _versionTitleLab.textAlignment = NSTextAlignmentLeft;
    [_versionTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
    }];
    
    _versionContentLab = [[QMUILabel alloc]init];
    [contentView2 addSubview:_versionContentLab];
    _versionContentLab.text = @"--";
    _versionContentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
    _versionContentLab.font = kSYSTEMFONT(14);
    _versionContentLab.textAlignment = NSTextAlignmentLeft;
    [_versionContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.snContentLab);
        make.centerY.mas_offset(0);
    }];
    

    
    
}


@end
